//
//  JulebuxqViewController.m
//  Xiangmu
//
//  Created by 이경인 on 2017/10/22.
//  Copyright © 2017年 LIJINGREN. All rights reserved.
//

#import "JulebuxqViewController.h"
#import "AFNetworking.h"
#import "UIImageView+WebCache.h"
#import "julebuxqTableViewCell.h"
@interface JulebuxqViewController ()<UITableViewDelegate,UITableViewDataSource>{
    
    NSArray *dateArr;
    UITableView *tableview;
    
    
}

@end

@implementation JulebuxqViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
    
    dateArr = [NSArray array];
    
    tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height) style: UITableViewStylePlain];
    tableview.delegate=self;
    tableview.dataSource=self;
    [self.view addSubview:tableview];
    [self initwithdate];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *str = @"julebuxqTableViewCell";
    julebuxqTableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:str];
    if (cell==nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:str owner:self options:nil]lastObject];
        NSDictionary *dict =dateArr[indexPath.row];
        cell.julebuname.text = dict[@"club_name"];
        cell.julebudidian.text = dict[@"district_name"];
        [cell.julebuimage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://172.24.10.175/workout/Uploads/%@",dict[@"thumb"]]]];
        
    }
    return cell;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return dateArr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 300;
}
-(void)initwithdate{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setObject:self.ID forKey:@"id"];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"http://172.24.10.175/workout/api.php/lists/mod/club" parameters:dict progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        dateArr =responseObject;
        [tableview reloadData];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}
@end

